package demo12.gumballRemote;

public class SoldState implements State{
	private static final long serialVersionUID = 2L;
    transient GumballMachine gumballMachine;
 
    public SoldState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

	@Override
	public void insertQuarter() {
		System.out.println("请稍等，我们已经给你一个口香糖");
	}
 
	@Override
	public void ejectQuarter() {
		System.out.println("对不起，你已经转动曲柄了。");
	}
 
	@Override
	public void turnCrank() {
		System.out.println("转了两圈不会让你另一个口香糖!");
	}
 
	@Override
	public void dispense() {
		gumballMachine.releaseBall();
		if (gumballMachine.getCount() > 0) {
			gumballMachine.setState(gumballMachine.getNoQuarterState());
		} else {
			System.out.println("正在出糖果!");
			gumballMachine.setState(gumballMachine.getSoldOutState());
		}
	}

 
	@Override
	public String toString() {
		return "分配一个口香糖";
	}

}
